<?php require_once('../Connections/media.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}
$colname_rsAnun = "-1";
if (isset($_GET['anunID'])) {
  $colname_rsAnun = $_GET['anunID'];
}
mysql_select_db($database_media, $media);
$query_rsAnun = sprintf("SELECT * FROM media WHERE ID = %s", GetSQLValueString($colname_rsAnun, "int"));
$rsAnun = mysql_query($query_rsAnun, $media) or die(mysql_error());
$row_rsAnun = mysql_fetch_assoc($rsAnun);
$totalRows_rsAnun = mysql_num_rows($rsAnun);


if ((isset($_GET['anunID'])) && ($_GET['anunID'] != "")) {
  $deleteSQL = sprintf("DELETE FROM media WHERE ID=%s",
                       GetSQLValueString($_GET['anunID'], "int"));

 mysql_select_db($database_media, $media);
  $Result1 = mysql_query($deleteSQL, $media) or die(mysql_error());
 
unlink("../media/img/".$row_rsAnun['nombrearchivo']);

  $deleteGoTo = "index.php";
  /*if (isset($_SERVER['QUERY_STRING'])) {
    $deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?";
    $deleteGoTo .= $_SERVER['QUERY_STRING'];
  }*/
  header(sprintf("Location: %s", $deleteGoTo));
}

mysql_free_result($rsAnun);
?>
